package slim3.dao;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.PersistenceManager;

import org.slim3.jdo.GenericDao;
import org.slim3.util.BeanMap;
import org.slim3.util.BeanUtil;

import slim3.model.Task;
import slim3.model.TaskMeta;

public class TaskDao extends GenericDao<Task> {

    private static final TaskMeta m = new TaskMeta();

    public TaskDao() {
        super(Task.class);
    }

    public TaskDao(PersistenceManager pm) throws NullPointerException {
        super(Task.class, pm);
    }

    public List<Task> findAll(boolean finished, CategoryDao categoryDao) {
        // List<Task> list =
        // from().where(m.finished.eq(finished)).getResultList();
        // List<BeanMap> taskList = new ArrayList<BeanMap>(list.size());
        // for (Task t : list) {
        // BeanMap m = new BeanMap();
        // BeanUtil.copy(t, m);
        // taskList.add(m);
        // }
        // return taskList;
        List<Task> list = from().where(m.finished.eq(finished)).getResultList();
//        for (Task t : list) {
//            System.out.println("findAll cate key : " + t.getCategoryKey());
//            if (t.getCategoryKey() != null) {
//                t.setCategory(categoryDao.find(t.getCategoryKey()));
//            }
//            System.out.println("findAll category: " + t.getCategory());
//        }
        return list;
    }
}
